/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.helper.EncCommonHelper;
import com.minierp.model.Establishment;
import com.minierp.model.EstablishmentContact;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class EstablishmentListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"EstablishmentList.xls\"");
		String type = (String) model.get("type");
		String typeName = "";
		if (type.equals("CLIENT")) {
			typeName = "客户";
		} else if (type.equals("COOPERATOR")) {
			typeName = "外协商";
		} else if (type.equals("PROVIDER")) {
			typeName = "供应商";
		}

		List list = (List) model.get("list");
		List contList = (List) model.get("contList");
		List typeList = (List) model.get("typeList");
		List leveList = (List) model.get("leveList");
		List areaList = (List) model.get("areaList");
		List tsList = (List) model.get("tsList");
		HSSFCellStyle norStyle = workbook.createCellStyle();
		norStyle.setBorderBottom(1);
		norStyle.setBorderTop(1);
		norStyle.setBorderLeft(1);
		norStyle.setBorderRight(1);
		HSSFSheet sheet = workbook.createSheet(typeName);
		HSSFRow r = sheet.createRow(0);
		byte colIndex = 0;
		HSSFCell c = r.createCell((short) colIndex);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("编号"));
		int arg20 = colIndex + 1;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("名称"));
		++arg20;
		if (type.equals("CLIENT")) {
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString("单位类别"));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString("单位等级"));
			++arg20;
		}

		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("电话"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("传真"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("email"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("公司网站"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("地区"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("邮编"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("地址"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("联系人"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("联系人电话"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("备注"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("经办人"));
		++arg20;
		c = r.createCell((short) arg20);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("帐套"));
		++arg20;

		int os;
		for (os = 0; os < list.size(); ++os) {
			Establishment objs = (Establishment) list.get(os);
			r = sheet.createRow(os + 1);
			colIndex = 0;
			c = r.createCell((short) colIndex);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getEstCode()));
			arg20 = colIndex + 1;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getEstName()));
			++arg20;
			if (type.equals("CLIENT")) {
				c = r.createCell((short) arg20);
				c.setCellStyle(norStyle);
				c.setCellValue(new HSSFRichTextString(EncCommonHelper
						.getSimpleObjectName(typeList, objs.getEstTypeId())));
				++arg20;
				c = r.createCell((short) arg20);
				c.setCellStyle(norStyle);
				c.setCellValue(new HSSFRichTextString(EncCommonHelper
						.getSimpleObjectName(leveList, objs.getEstLevelId())));
				++arg20;
			}

			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getPhone()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getFax()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getEmail()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getWebSite()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(EncCommonHelper
					.getSimpleObjectName(areaList, objs.getAreaId())));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getPostcode()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getAddress()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getLinkman()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getLinkmanPhone()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getMark()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(objs.getManagerName()));
			++arg20;
			c = r.createCell((short) arg20);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(EncCommonHelper
					.getSimpleObjectName(tsList, objs.getTallySetId())));
			++arg20;
		}

		sheet = workbook.createSheet("联系人");
		r = sheet.createRow(0);
		c = r.createCell(0);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString(typeName + "名称"));
		c = r.createCell(1);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("联系人姓名"));
		c = r.createCell(2);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("性别"));
		c = r.createCell(3);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("职务"));
		c = r.createCell(4);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("手机"));
		c = r.createCell(5);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("Email"));
		c = r.createCell(6);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("电话"));
		c = r.createCell(7);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("QQ"));
		c = r.createCell(8);
		c.setCellStyle(norStyle);
		c.setCellValue(new HSSFRichTextString("备注"));

		for (os = 0; os < contList.size(); ++os) {
			Object[] arg22 = (Object[]) contList.get(os);
			EstablishmentContact ec = (EstablishmentContact) arg22[1];
			r = sheet.createRow(os + 1);
			c = r.createCell(0);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) arg22[0]));
			c = r.createCell(1);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getContactName()));
			c = r.createCell(2);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getSex()));
			c = r.createCell(3);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getPossie()));
			c = r.createCell(4);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getMobile()));
			c = r.createCell(5);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getEmail()));
			c = r.createCell(6);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getPhone()));
			c = r.createCell(7);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getIm()));
			c = r.createCell(8);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString(ec.getMark()));
		}

		ServletOutputStream arg21 = response.getOutputStream();
		workbook.write(arg21);
		arg21.flush();
		arg21.close();
	}
}